<!DOCTYPE html>
<html lang="ch">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TestAPI</title>
</head>
<body>
    <input type="text" id="message">
    <button type="submit" id="submit">提交</button>

    <script>
        let websocket = new WebSocket("ws://127.0.0.1:8080/test");
        websocket.onopen = function() {
            console.log("WebSocket已连接");
        };
        websocket.onmessage = function(e) {
            console.log("收到来自服务器的消息：", e.data);
        };
        websocket.onerror = function() {
            console.log("WebSocket发生了错误");
        };
        websocket.onclose = function() {
            console.log("WebSocket已关闭");
        };
        let input = document.querySelector("#message");
        let button = document.querySelector("#submit");
        button.onclick = function() {
            console.log("发送消息" + input.value);
            
            websocket.send(input.value);

        }
    </script>
</body>
</html>